#include<bits/stdc++.h>
using namespace std;
int a[200001];
int lz = -1,n;
void dfs(int dep,int r,int b,int sum)
{
    if(dep == n+1)
    {
        lz = max(lz,sum);
        return;
    }
    if(a[dep] == r)
    {
        dfs(dep+1,r,b,sum+a[dep]);
        dfs(dep+1,r,a[dep],sum);
    }
    else if(a[dep] == b)
    {
        dfs(dep+1,r,b,sum+a[dep]);
        dfs(dep+1,a[dep],b,sum);
    }
    else
    {
        dfs(dep+1,a[dep],b,sum);
        dfs(dep+1,r,a[dep],sum);
    }
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin >> t;
    for(int i = 1;i <= t;i++)
    {
       cin >> n;
       for(int i = 1;i <= n;i++)
       {
           cin >> a[i];
       }
       dfs(1,0,0,0);
       cout << lz << endl;
       lz = -1;
    }
    return 0;
}

